package com.lib.controller.databoard;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.lib.model.dao.DataBoardDao;
import com.lib.model.dto.DataBoardDto;
import com.lib.paging.ResultLists;

@Controller
public class DataboardController {
	
	@Autowired
	private com.lib.model.service.IDataBoardService dataBoardService;

	@RequestMapping("/datalist.do")
	public ModelAndView dataList(HttpServletRequest request, HttpServletResponse resopnse){
		
		ModelAndView mav = new ModelAndView();
		String sstartPage= request.getParameter("startPage");
		String sstartBlock= request.getParameter("startBlock");
		String searchType = request.getParameter("searchType");
		String searchValue = request.getParameter("searchValue");
		
		int startPage = 1;
		int startBlock = 1;
		if (sstartPage != null) {
			startPage = Integer.parseInt(sstartPage);
		}
		if (sstartBlock != null) {
			startBlock = Integer.parseInt(sstartBlock);
		}
		
		ResultLists<DataBoardDto> list = dataBoardService.getAllDataBoardList(startPage,startBlock, searchType,  searchValue);

		mav.addObject("dataList",list);
		mav.setViewName("databoardlist");
		
		return mav;
	}
	
	@RequestMapping("/datadetail.do")
	public ModelAndView dataDetail(HttpServletRequest request, HttpServletResponse resopnse){
		
		ModelAndView mav = new ModelAndView();
		String databoard_num = request.getParameter("databoard_num");
		
		System.out.println(databoard_num);
		DataBoardDto dto = dataBoardService.getDataBoardDetail(databoard_num);
		System.out.println(dataBoardService.dataBoardCount(databoard_num));
		
		mav.addObject("detailDto",dto);
		mav.setViewName("datadetail");
		return mav;
	}
	
	@RequestMapping("/databoardwrite.do")
	public ModelAndView databoardwirte(){
		ModelAndView mav = new ModelAndView();
		
		mav.setViewName("datawrite");
		
		return mav;
	}
	
	

	
}
